﻿//该js功能为获取用户详细页信息
var uid=(GetRequest().id);
function GetRequest()
{
    var url = location.search;   //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1)
    {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++)
        {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
$.ajax({
    url: "./user?id="+uid,
    method: "GET",
    dataType: "json"
}).done(function (result) {
    updateUserInfo(result.userinfo,result.isOthers);
})
function fan() {
    $.ajax({
        url: "./fan?id="+uid,
        method: "GET",
        dataType: "text",
    }).done(function (result) {
        alert(result);
    })
}
function updateUserInfo(user,isOthers) {
    if(isOthers=="TRUE")
    {
        $("#aboutUser").text("关于他");
        $(".isMe").remove();
        $(".fanButton").css("visibility","visible");
    }
    var date = new Date();
    var startDate = new Date(user.birthday);
    var newDate = date.getTime() - startDate.getTime();
    var age = Math.ceil(newDate / 1000 / 60 / 60 / 24 / 365);
    $("#user_age").val(judegIsNull(age));
    $("#user_birthday").val(judegIsNull(user.birthday));
    $("#user_name").val(judegIsNull(user.nickname));
    $("#user_location").val(judegIsNull(user.location));
    $("#user_signature").val(judegIsNull(user.signature));
    $("#man").attr("checked",'checked')
    if(user.sex=="1")
        $("#man").attr("checked",'checked')
    else
        $("#woman").attr("checked",'checked')
    if(user.avatar!="null")
        $(".largeAvatar").attr("src","/MySpace/avatar/"+user.avatar);
}

function judegIsNull(info) {

    if (info == "null") {
        return "";
    } else
        return info;
}